package com.karolak.stock.oscilator;

import java.util.List;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

public class CrossFreeOsc extends Indicator {

	/**
	 * @param dataManager
	 * @param period
	 * @param input
	 */
	public CrossFreeOsc(DataManager dataManager, int period, Indicator indicator) {
		super(dataManager, period, indicator);
	}

	public double execute(double x) {
		if (getPeriod() == 0) {
			return 0;
		}
		List<Double> values = getDataManager().getData(getInput().getName(), getPeriod());
		int size = values.size();
		int i = 0;
		for (i = 0; i < size; i++) {
			double v = values.get(size - 1 - i);
			if (v != 0) {
				return i;
			}
		}
		return i;
	}
}
